#define  _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    int uniquePaths(int m, int n) {
        vector<vector<int>> memo(m, vector<int>(n));
        memo[0][0] = 1;
        function<int(int, int)>
            dfs = [&](int r, int c)->int
            {
                if (r < 0 || c < 0) return 0;
                if (memo[r][c]) return memo[r][c];
                return memo[r][c] = dfs(r - 1, c) + dfs(r, c - 1);
            };
        return dfs(m - 1, n - 1);
    }
};